<extend name="layout/edit" />

<block name="content">
    <div style="padding: 10px;height: 100%;">
        <control:Form id="form"/>
    </div>
</block>

<block name="footer">
   <script type="text/javascript">
    var  page=(function(ns){
        
        
        //页面初始化
        ns.init=function(){
            $("#sms_link").parent().attr('id','sms_url');
            ns.setSmsLink();
        }
        
        ns.setSmsLink=function(){
            if(form.getValue('type') == 'submail'){
                $("#sms_url").html("<a class='link' target='_target' href='https://www.mysubmail.com'>去获取https://www.mysubmail.com</a>");
                form.setReadonly('tmp_code',false,false); 
                form.setReadonly('content',true,true); 
                form.setReq('sign_name',false); 
                form.setReq('SdkAppId',false); 
                $("input[name='tmp_code']").parents('.table-cell').hide();
                $("textarea[name='content']").parents('.table-cell').show();
                $("input[name='SdkAppId']").parents('.table-cell').hide();
            } else if(form.getValue('type') == 'tsms'){
                $("#sms_url").html("<a class='link' target='_target' href='https://console.cloud.tencent.com/smsv2'>去获取https://console.cloud.tencent.com/smsv2</a>");
                form.setReadonly('tmp_code',true,true); 
                form.setReadonly('content',false,false); 
                form.setReq('sign_name',true); 
                form.setReq('SdkAppId',true); 
               	$("input[name='tmp_code']").parents('.table-cell').show();
                $("textarea[name='content']").parents('.table-cell').hide();
                $("input[name='SdkAppId']").parents('.table-cell').show();
            } else{
                $("#sms_url").html("<a class='link' target='_target' href='https://www.aliyun.com/product/sms'>去获取https://www.aliyun.com/product/sms</a>");
                form.setReadonly('tmp_code',true,true); 
                form.setReadonly('content',false,false); 
                form.setReq('sign_name',false); 
                form.setReq('SdkAppId',false); 
                $("input[name='tmp_code']").parents('.table-cell').show();
                $("textarea[name='content']").parents('.table-cell').hide();
                $("input[name='SdkAppId']").parents('.table-cell').hide();
            }
        }
        
        //保存
        ns.save=function(callback){
            var data = form.getData();
            if(!data) return false;
            $.ajaxs("/admin/soft/param/saveTextParamValue",{
                param_scope:'系统基础配置',
                param_code:'system_base_config_sms',
                param_value: JSON.stringify(form.getData())
            }).then(function(res){
                if(callback){
                    callback();
                }else{
                    $.toast(1,'保存成功！');
                }
            });
        }
        
        //效验
        ns.verify = function(){
            ns.save(function(){
                layer.prompt({title: '请输入手机号，并确认', formType: 3}, function(pass, index){
                    $.ajaxs("/api/soft/sms/sendCode",{
                        phone:pass,
                    }).then(function(res){
                        $.toast(1,'效验通过，请注意查收短信！');
                        layer.close(index);
                    });
                });
            });
        }
        
        return ns;
    }({}));
    
    //加载当前页面需要的控件和配置
    $(function(){  page.init();  });
   </script>
</block>



<block name="HEADER">
   <style type="text/css">
        .xw-form .xw-btnRow{
           text-align: left !important;
            padding-left: 180px !important;
            background: none; 
            border: none;
        }
        .xw-form .layui-tab .layui-tab-title li{
            font-weight:100 ;
        }
        .link{   line-height: 30px; }
   </style>
</block>